package entity;

import dto.GSTDAccount;
import dto.PropertyField;
import entity.fields.properties.Street;
import entity_controllers.OptionManager;

public class Account extends GSTDAccount {

	private boolean isBankrupt;
	private OptionManager optionManager = new OptionManager();
	private OptionManager effectManager = new OptionManager();

	public Account(int startingBalance) {
		super(startingBalance);
	}

	/*******************************************************************************
	 * ** REMEMBER TO ADD THE METHOD BELOW AND THE CONSTRUCTOR TO GSTDAccount ** *
	 *******************************************************************************/

	@Override
	public int getTotalAssets() {
		PropertyField[] property = getProperties();

		int sum = super.getTotalAssets();

		// Add the prices of all owned fields' buildings to the sum
		for (int i = 0; i < property.length; i++) {
			if (property[i].getClass() == Street.class) {
				sum += ((Street) property[i]).getBuildings() * ((Street) property[i]).getHousePrice();
			}
		}

		return sum;
	}

	@Override
	protected void reset() {
		optionManager.reset();
		effectManager.reset();
	}

	public boolean isBankrupt() {
		return isBankrupt;
	}

	public void setBankrupt(boolean isBankrupt) {
		this.isBankrupt = isBankrupt;
	}

	public OptionManager getOM() {
		return optionManager;
	}

	public OptionManager getEM() {
		return effectManager;
	}

	public boolean hasBuildings() {
		for (int i = 0; i < getProperties().length; i++) {
			if (getProperties()[i].getClass().equals(Street.class))
				if (((Street) getProperties()[i]).getBuildings() > 0)
					return true;
		}
		return false;
	}

}
